'''
线程中全局变量调用的问题
线程是可以共享全局变量的
'''
import threading
from time import sleep

ticket = 1000

def run1():
	global ticket
	for i in range(100):
		sleep(0.01)
		ticket -= 1
		
'''
def run2():
	global ticket
	for i in range(100):
		ticket -= 1
'''	
	
if __name__ == '__main__':
	t1 = threading.Thread(target=run1, name='th1')
	
	t2 = threading.Thread(target=run1, name='th2')
	t3 = threading.Thread(target=run1, name='th3')
	t4 = threading.Thread(target=run1, name='th4')
	t1.start()
	t2.start()
	t3.start()
	t4.start()
	
	t1.join()
	t2.join()
	t3.join()
	t4.join()
	
	print(ticket)